package com.company.project.action;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.struts2.ServletActionContext;

import com.company.project.bean.Goods;
import com.company.project.bean.Order;
import com.company.project.bean.ShopCar;
import com.company.project.bean.User;
import com.company.project.service.GoodsService;
import com.company.project.service.OrderService;
import com.opensymphony.xwork2.ActionSupport;


@SuppressWarnings("all")
public class OrderAction extends ActionSupport{
	
	private int gid;
	private OrderService orderService;
	private GoodsService goodsService;
	private List<?> list;
	private List<?> list2;
	private ShopCar shopcar;
	private Order order;
	
	public int getGid() {
		return gid;
	}

	public void setGid(int gid) {
		this.gid = gid;
	}

	

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	
	public String addOrder(){
		User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
		Order order = new Order();
		order.setBuytime(new Date());
		Goods g = goodsService.getById(gid);
		System.out.println(g.getId());
		//order.setBuytime(new Date());
		order.setGoods(g);
	
		order.setStatus("0");
		order.setTotal(22f);
		order.setUser(user);	
		orderService.saveorder(order);
		return SUCCESS;
		
	}
	//用户查看订单
	public String showOrder(){
		
		list=orderService.findByUid((User) ServletActionContext.getRequest().getSession().getAttribute("user"));
		//order.setStatus("1");
		
		return SUCCESS;
	}
	
	//后台查看订单
	public String orderList(){
		 list2=orderService.findAll();
		return SUCCESS;
	}
	
	
	//后台处理订单
	public String dealorder(){
		order = orderService.findById(order.getId());
		order.setStatus("1");
		orderService.updateOrder(order);
		return SUCCESS;
	}
	
	

	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	public List<?> getList() {
		return list;
	}

	public void setList(List<?> list) {
		this.list = list;
	}

	public List<?> getList2() {
		return list2;
	}

	public void setList2(List<?> list2) {
		this.list2 = list2;
	}

	public ShopCar getShopcar() {
		return shopcar;
	}

	public void setShopcar(ShopCar shopcar) {
		this.shopcar = shopcar;
	}

	public void setGoodsService(GoodsService goodsService) {
		this.goodsService = goodsService;
	}
	
	
	
}
